﻿using System;

class DrawBigMatrix
{
    static void Main()
    {
        int numberN;

        Console.WriteLine("Type a number:");
        bool isFirstNumberValid = int.TryParse(Console.ReadLine(), out numberN);

        int indexX = 0;
        int indexY = 0;
        int number = 1;

        if (isFirstNumberValid)
        {
            int[,] array = new int[numberN, numberN];
            array[0, 0] = 1;

            while (number <= numberN * numberN)
            {
                while (true)
                {
                    array[indexX, indexY] = number;
                    number++;  

                    if (isInRange(array, indexX+1, indexY) && array[indexX+1, indexY] == 0)
                    {
                        indexX++;
                        continue;
                      
                    }
                    else
                    {
                        indexY++;
                        break;
                    }
                }

                while (true)
                {
                    array[indexX, indexY] = number;
                    number++;

                    if (isInRange(array, indexX, indexY + 1) && array[indexX, indexY + 1] == 0)
                    {
                        indexY++;
                        continue;

                    }
                    else
                    {
                        indexX--;
                        break;
                    }
                }

                while (true) 
                {
                    array[indexX, indexY] = number;
                    number++;

                    if (isInRange(array, indexX - 1, indexY) && array[indexX - 1, indexY] == 0)
                    {
                        indexX--;
                        continue;

                    }
                    else
                    {
                        indexY--;
                        break;
                    }
                }

                while (true)
                {
                    array[indexX, indexY] = number;
                    number++;

                    if (isInRange(array, indexX, indexY - 1) && array[indexX, indexY - 1] == 0)
                    {
                        indexY--;
                        continue;

                    }
                    else
                    {
                        indexX++;
                        break;
                    }
                }


            }
            Console.WriteLine();
        }
        else
        {
            Console.WriteLine("Your input isn`t OK!!!");
        }
    }

    static bool isInRange(int[,] array, int indexX, int indexY)
    {
        if (indexX < array.GetLength(0) && indexY < array.GetLength(1))
        {
            return true;   
        }
        else
        {
            return false;
        }
    }
}